<?php

namespace addons\config\model;

class Notice extends \web\common\model\BaseModel{
    
    protected function _initialize(){
        $this->tableName = 'sys_notice';
    }
    
    public function getNoticeList($pageIndex = 0, $pageSize = 10, $filter = '', $order = 'id desc'){
        $sql = 'select * from ' . $this->getTableName().' where status = 1';
        if (!empty($filter))
            $sql .= ' and ' .$filter;

        if ($pageIndex <= 0 && $pageSize < 0) {
            $pageIndex = 0;
            $pageSize = 10;
        }
        $offset = 0;
        if ($pageIndex > 0)
            $offset = (intval($pageIndex) - 1) * intval($pageSize);
        $sql .= ' order by id desc limit ' . $offset . ',' . $pageSize;
        return $this->query($sql);
    }
    
    
    public function getNoticeDetail($id = 0, $pageIndex = -1, $pageSize = -1, $filter = '') {

        $sql = 'select * from ' . $this->getTableName() . ' where id = '.$id;
        if (!empty($filter))
            $sql .= ' and ' . $filter;
        $order = "id asc";
        return $this->getDataListBySQL($sql, $pageIndex, $pageSize, $order);
    }
}
